home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Snippets / OS Utilities / TestGestalt / TestVM / Source / TestGestalt.c
Encoding:
C/C++ Source or Header  |  1996-09-17  |  1.2 KB  |  73 lines  |  [TEXT/CWIE]

  1. #ifndef __CTYPE__
  2. #include <CType.h>
  3. #endif
  4.  
  5. #ifndef __OSUTILS__
  6. #include <OSUtils.h>
  7. #endif
  8.  
  9. #ifndef __STDIO__
  10. #include <StdIO.h>
  11. #endif
  12.  
  13. #ifndef __GESTALTEQU__
  14. #include <GestaltEqu.h>
  15. #endif
  16.  
  17. #ifndef __TYPES__
  18. #include <Types.h>
  19. #endif
  20.  
  21. #include <Traps.h>
  22.  
  23. #define    TRUE            0xFF
  24. #define    FALSE            0
  25.  
  26. Boolean TrapAvailable(short theTrap);
  27.  
  28.  
  29. // check to see if a given trap is implemented. We follow IM VI-3-8.
  30. Boolean TrapAvailable(short theTrap)
  31. {
  32.     TrapType theTrapType;
  33.     short numToolboxTraps;
  34.     
  35.     if ((theTrap & 0x0800) > 0)
  36.         theTrapType = ToolTrap;
  37.     else
  38.         theTrapType = OSTrap;
  39.  
  40.     if (theTrapType == ToolTrap)
  41.     {
  42.         theTrap = theTrap & 0x07ff;
  43.         if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xaa6e, ToolTrap))
  44.             numToolboxTraps = 0x0200;
  45.         else
  46.             numToolboxTraps = 0x0400;
  47.         if (theTrap >= numToolboxTraps)
  48.             theTrap = _Unimplemented;
  49.     };
  50.  
  51.     return (NGetTrapAddress(theTrap, theTrapType) != NGetTrapAddress(_Unimplemented, ToolTrap));
  52. }
  53.  
  54.  
  55. void main()
  56. {
  57. OSErr        err;
  58. long        feature;
  59.  
  60. if (TrapAvailable(_Gestalt)) {
  61.     err = Gestalt(gestaltVMAttr, &feature);
  62.     if (!err) {
  63.         if (feature & 0x0001)
  64.             printf ("We have VM\n");
  65.         else
  66.             printf ("We don't have VM\n");
  67.         }
  68.     else 
  69.         printf ("Gestalt err = %i\n",err);
  70.     }
  71. else
  72.     printf ("No Gestalt\n");
  73. }